/*
 * WeatherManagerConsole
 * 
 * Copyright 2008-2009 Centro Andaluz de Innovaci�n y Tecnolog�as de la
 * Informaci�n y las Comunicaciones (CITIC). All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * Please contact CITIC - Edificio CITIC, C/ Marie Curie, 6 Parque
 * Tecnol�gico de Andaluc�a 29590 - Campanillas, M�laga, Spain
 * or visit www.citic.es, if you need additional information or
 * have any questions.
 */

package es.citic.puedes.weather.weathermanager.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import es.citic.puedes.weatherservice.IWeatherManager;
import es.citic.puedes.weatherservice.impl.bbdd.WeatherDataBase;
import es.citic.puedes.weatherservice.model.Language;
import es.citic.puedes.weatherservice.utils.DataConfigManager;

public class WeatherManagerConsole {
	public static final String CITY = "Marbella";
	public static final String COUNTRY = "España";
	public static final Integer USER = 1;
	public static final Language LANGUAGE = Language.SPANISH;
	public static final int DAYS = 5;

	private static IWeatherManager PVA_01(String configFile, WeatherDataBase dataBase) {
		return (PVA_01_WeatherManagerTest.test(configFile, dataBase));
	}

	private static void PVA_02(IWeatherManager wm, String city) {
		PVA_02_WeatherManagerTest.test(wm, city);
	}

	private static void PVA_03(IWeatherManager wm, String city, String country,
			int days, Language lang, Integer user) {
		PVA_03_WeatherManagerTest.test(wm, city, country, days, lang, user);
	}

	private static void PVA_04(IWeatherManager wm, int user, Language language) {
		PVA_04_WeatherManagerTest.test(wm, user, language);
	}

	public static void main(String[] args) {
		boolean finished = false;
		
		WeatherDataBase dataBase = new WeatherDataBase(new DataConfigManager("META-INF/config.xml").getValueFromConfigXml("weathermanager","constants", "persistence_unit"));
		
		IWeatherManager wm = PVA_01("META-INF/config.xml", dataBase);

		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(input);

		try {
			while (!finished) {
				System.out.println("\nValidation Test List");
				System.out.println("1. PVA_01");
				System.out.println("2. PVA_02");
				System.out.println("3. PVA_03");
				System.out.println("4. PVA_04");
				System.out.println("Enter an option (0 to exit)--> ");

				// read in user input				
				int option = 0;
				boolean correct = false;
				while (!correct){
					try {
						String string = reader.readLine();
						option = Integer.parseInt(string);
						correct = true;

					} catch (Exception e) {
						System.out.println("Invalid option. Try again.");
					}
				}				

				switch (option) {
				case 0:
					finished = true;
					break;
				case 1:
					System.out.println("Result: OK!");
					break;
				case 2:
					PVA_02(wm, CITY);
					break;
				case 3:
					PVA_03(wm, CITY, COUNTRY, DAYS, LANGUAGE, USER);
					break;			
				case 4:
					PVA_04(wm, USER, LANGUAGE);
					break;

				default:
					break;
				}
			}
		} finally {
			try {
				input.close();
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
